<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>添加分类</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="${ctx }/layui/css/layui.css" media="all" />
<script>  
        <%--JS gloable varilible--%>  
        var ctx = "${ctx}";  
    </script>  
<style type="text/css">
.layui-form-item .layui-inline {
	width: 33.333%;
	float: left;
	margin-right: 0;
}

@media ( max-width :1240px) {
	.layui-form-item .layui-inline {
		width: 100%;
		float: none;
	}
}
</style>
</head>
<body class="childrenBody">
	<form class="layui-form" style="width: 80%;" id="aaf">
		<div class="layui-form-item" style="margin-top:10px">
			<label class="layui-form-label">分类名</label>
			<div class="layui-input-block">
				<input type="text" id="category" class="layui-input category"
					lay-verify="required" placeholder="请输入分类名" name="category" value="" autocomplete="off">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" type="bottom" lay-submit="" id="addCategory">立即提交</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="${ctx }/layui/layui.js"></script>
	<script>
	var $;
	layui.config({
		base : "js/"
	}).use(['form','layer','jquery'],function(){
		var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage;
		$ = layui.jquery;
		$("#addCategory").on("click",function(){
			var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
	 		var msg;
	 		$.ajax({
	 			type: "post",
	            url: ctx+"/category/insCategory",
	            data:{category:$("#category").val()},
				dataType:"json",
				success:function(d){
					console.log(d)
					if(d.code==0){
			        	msg="添加成功！";
					}else{
			        	msg=d.msg;
					}
				}
	 		});
	 		setTimeout(function(){
	 			top.layer.close(index);
	 			top.layer.msg(msg);
	 			layer.closeAll("iframe");
	 			//刷新父页面
		 		parent.location.reload();
	        },1000);
	 		return false;
		}); 		
		
	})
	</script>
</body>
</html>